/**
 * The base joint class. Joints are used to constraint two bodies together in
 * various fashions. Some joints also feature limits and motors.
 * 
 * JNI Wrapper notes:
 *     As this class is not to be instantiated, there is no need for underlying
 * implementation. The methods implemented(wrapped, or rather) are forwarded to 
 * the subclasses.
**/
public class b2Joint extends b2AllocationGuard {

	b2Body m_bodyA;
	b2Body m_bodyB;
	b2Joint m_next;

	public b2Joint(int addr) {
		super(addr);
	}

	@Override
	public void release() {
		super.release();
	}

	/**Get the type of the concrete joint.*/
	public b2JointType GetType() {
		int type = jniGetType(address);
		b2JointType[] types = b2JointType.values();
		return types[type];
	}

	/**Get the first body attached to this joint.*/
	public b2Body GetBodyA() {
		return m_bodyA;
	}

	/**Get the second body attached to this joint.*/
	public b2Body GetBodyB() {
		return m_bodyB;
	}

	/**(abstract)Get the anchor point on bodyA in world coordinates.*/
	public b2Vec2 GetAnchorA() {
		return null;
	}

	/**(abstract)Get the anchor point on bodyB in world coordinates.*/
	public b2Vec2 GetAnchorB() {
		return null;
	}

	/**(abstract)Get the reaction force on bodyB at the joint anchor in Newtons.*/
	public b2Vec2 GetReactionForce(float inv_dt) {
		return null;
	}

	/**(abstract)Get the reaction torque on bodyB in N*m.*/
	public float GetReactionTorque(float inv_dt) {
		return 0;
	}

	/**Get the next joint the world joint list.*/
	public b2Joint GetNext() {
		return m_next;
	}

	/**Short-cut function to determine if either body is inactive.*/
	public boolean IsActive() {
		return jniIsActive(address);
	}

	/**
	 * Get collide connected.
	 * Note: modifying the collide connect flag won't work correctly because
	 * the flag is only checked when fixture AABBs begin to overlap.
	**/
	public boolean GetCollideConnected() {
		return jniGetCollideConnected(address);
	}

	private static native int jniGetType(int me);
	private static native boolean jniIsActive(int me);
	private static native boolean jniGetCollideConnected(int me);
}
